/*

Replication code for Mark Manger and Thomas Sattler, forthcoming, 
"The origins of persistent current account imbalances in the post-Bretton Woods era", 
Comparative Political Studies. 

Note: requires estout and ivreg2 packages; type "net search estout" and "net search ivreg2" if needed

*/


use "MangerSattlerCPS_Data", clear

set more off


*********
* Table 2
*********

mixed tb coord_m govtDeficit_c stockcap_gdp_i_c finmed_gdp_i_c old_c young_c rgdppc_ppp_c rgrowth_c dtotindex_pc_c dprivateCredit_c fuelExports_c kaopen_c ability1_c eurocrisis y1978-y2015 || imfcode: , stddev
scalar sd_cons = exp(_b[lns1_1_1:_cons])
estadd scalar sd_cons
estimates store m1

mixed tb coord_m govtDeficit_c stockcap_gdp_i_c finmed_gdp_i_c old_c young_c rgdppc_ppp_c rgrowth_c dtotindex_pc_c dprivateCredit_c fuelExports_c kaopen_c ability1_c eurocrisis || imfcode: , stddev
scalar sd_cons = exp(_b[lns1_1_1:_cons])
estadd scalar sd_cons
estimates store m2

mixed tb coord_75 govtDeficit_c stockcap_gdp_i_c finmed_gdp_i_c old_c young_c rgdppc_ppp_c rgrowth_c dtotindex_pc_c dprivateCredit_c fuelExports_c kaopen_c ability1_c eurocrisis y1978-y2015 || imfcode: , stddev
scalar sd_cons = exp(_b[lns1_1_1:_cons])
estadd scalar sd_cons
estimates store m3

mixed cu coord_m lnfa_c govtDeficit_c stockcap_gdp_i_c finmed_gdp_i_c old_c young_c rgdppc_ppp_c rgrowth_c dtotindex_pc_c dprivateCredit_c fuelExports_c kaopen_c ability1_c eurocrisis y1978-y2015 || imfcode: , stddev
scalar sd_cons = exp(_b[lns1_1_1:_cons])
estadd scalar sd_cons
estimates store m4

mixed cu coord_m lnfa_c govtDeficit_c stockcap_gdp_i_c finmed_gdp_i_c old_c young_c rgdppc_ppp_c rgrowth_c dtotindex_pc_c dprivateCredit_c fuelExports_c kaopen_c ability1_c eurocrisis || imfcode: , stddev
scalar sd_cons = exp(_b[lns1_1_1:_cons])
estadd scalar sd_cons
estimates store m5

mixed cu coord_75 lnfa_c govtDeficit_c stockcap_gdp_i_c finmed_gdp_i_c old_c young_c rgdppc_ppp_c rgrowth_c dtotindex_pc_c dprivateCredit_c fuelExports_c kaopen_c ability1_c eurocrisis y1978-y2015 || imfcode: , stddev
scalar sd_cons = exp(_b[lns1_1_1:_cons])
estadd scalar sd_cons
estimates store m6

esttab m1 m2 m3 m4 m5 m6 using "Table2.tex", replace nogaps title("Wage bargaining coordination, trade balance and current account: hierarchical models") ///
		mtitles("TB" "TB" "TB" "CU"  "CU"  "CU") nonumbers ///
		keep(coord_m coord_75 ///
		lnfa_c govtDeficit_c stockcap_gdp_i_c finmed_gdp_i_c old_c young_c rgdppc_ppp_c rgrowth_c dtotindex_pc_c dprivateCredit_c fuelExports_c kaopen_c ability1_c eurocrisis _cons) ///
		order(coord_m coord_75 ///
		lnfa_c govtDeficit_c stockcap_gdp_i_c finmed_gdp_i_c old_c young_c rgdppc_ppp_c rgrowth_c dtotindex_pc_c dprivateCredit_c fuelExports_c kaopen_c ability1_c eurocrisis _cons) ///
		drop(lns1_1_1:_cons lnsig_e:_cons) ///
		varlabels(coord_m "Coord\${i}\$" coord_75 "Coord(1975)\${i}\$"  ///
		lnfa_c "NFA\${i,t-1}\$" govtDeficit_c "Fiscal\${i,t}\$" stockcap_gdp_i_c "Stock\${i,t}\$" ///
		finmed_gdp_i_c "Intermed\${i,t}\$" old_c "Old\${i,t}\$" young_c "Young\${i,t}\$" rgdppc_ppp_c "GDPpc\${i,t}\$" rgrowth_c "Growth\${i,t}\$" dtotindex_pc_c "ToT\${i,t}\$" dprivateCredit_c "Credit\${i,t}\$" ///
		kaopen_c "KAOpen\${i,t}\$" fuelExports_c "FuelExp\${i,t}\$" ability1_c "OrigSin\${i,t}\$" eurocrisis "Eurocrisis\${i,t}\$" _cons Constant) ///
		cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.1 ** 0.05 *** 0.01) nonumbers ///
		stats(sd_cons p N, fmt(%9.2f %9.3f %9.0f) labels("Sd(Cons)" "$ p $" "$ N $")) ///
		legend label collabels(, none) style(tex) ///
		notes addnotes("Standard errors in parentheses. *** $ p<0.01 $, ** $ p<0.05 $, * $ p<0.1 $.")

		
**********
* Figure 3
**********

mixed tb coord_m govtDeficit_c stockcap_gdp_i_c finmed_gdp_i_c old_c young_c rgdppc_ppp_c rgrowth_c dtotindex_pc_c dprivateCredit_c fuelExports_c kaopen_c ability1_c eurocrisis || imfcode: , stddev
predict ra_tb, reffects reses(ra_sd_tb)
gen ahat_tb = (_b[_cons] + ra_tb) + _b[coord_m]*coord_m 
gen ahat_tb_lo = ahat_tb - ra_sd_tb
gen ahat_tb_hi = ahat_tb + ra_sd_tb
reg ahat_tb coord_m if year == 1978
predict yhat_tb
twoway scatter ahat_tb coord_m if year == 1978, msymbol(o) mcolor(black) mlabel(iso) ///
	|| rspike ahat_tb_lo ahat_tb_hi coord_m, lcolor(black) lwidth(vthin) ///
	|| line yhat_tb coord_m if year == 1978, lcolor(black) lwidth(vthin) ///
	ylabel(-6(2)8) yscale(range(-6 8)) ///
	ytitle("intercept (trade balance)") ///
	xtitle("wage bargaining coordination") ///
	legend(off) 
graph export Figure3a.pdf, replace	

	
mixed cu coord_m lnfa_c govtDeficit_c stockcap_gdp_i_c finmed_gdp_i_c old_c young_c rgdppc_ppp_c rgrowth_c dtotindex_pc_c dprivateCredit_c fuelExports_c kaopen_c ability1_c eurocrisis || imfcode: , stddev
predict ra_cu, reffects reses(ra_sd_cu)
gen ahat_cu = (_b[_cons] + ra_cu) + _b[coord_m]*coord_m 
gen ahat_cu_lo = ahat_cu - ra_sd_cu
gen ahat_cu_hi = ahat_cu + ra_sd_cu
reg ahat_cu coord_m if year == 1978
predict yhat_cu
twoway scatter ahat_cu coord_m if year == 1978, msymbol(o) mcolor(black) mlabel(iso)  ///
	|| rspike ahat_cu_lo ahat_cu_hi coord_m, lcolor(black) lwidth(vthin) ///
	|| line yhat_cu coord_m if year == 1978, lcolor(black) lwidth(vthin) ///
	ylabel(-4(2)4) yscale(range(-4 4)) ///
	ytitle("intercept (current account)") ///
	xtitle("wage bargaining coordination")	///
	legend(off) 
graph export Figure3b.pdf, replace	


*********
* Table 3
*********

mixed tb coord_m xr_fix c.coord_m#xr_fix govtDeficit_c stockcap_gdp_i_c finmed_gdp_i_c old_c young_c rgdppc_ppp_c ///
	rgrowth_c dtotindex_pc_c dprivateCredit_c fuelExports_c kaopen_c ability1_c eurocrisis ///
	y1978-y2015 || imfcode: xr_fix, stddev cov(unstruct)
scalar sd_xr = exp(_b[lns1_1_1:_cons])
scalar sd_cons = exp(_b[lns1_1_2:_cons])
scalar corr_cons_xr = _b[atr1_1_1_2:_cons]
estadd scalar sd_cons
estadd scalar sd_xr
estadd scalar corr_cons_xr
estimates store m7

mixed tb coord_m euro c.coord_m#euro govtDeficit_c stockcap_gdp_i_c finmed_gdp_i_c old_c young_c rgdppc_ppp_c ///
	rgrowth_c dtotindex_pc_c dprivateCredit_c fuelExports_c kaopen_c ability1_c eurocrisis ///
	y1978-y2015 || imfcode: euro, stddev cov(unstruct)
scalar sd_euro = exp(_b[lns1_1_1:_cons])
scalar sd_cons = exp(_b[lns1_1_2:_cons])
scalar corr_cons_euro = _b[atr1_1_1_2:_cons]
estadd scalar sd_cons
estadd scalar sd_euro
estadd scalar corr_cons_euro
estimates store m8

mixed tb coord_m euro1 euro2 c.coord_m#euro1 c.coord_m#euro2 govtDeficit_c stockcap_gdp_i_c finmed_gdp_i_c old_c young_c rgdppc_ppp_c ///
	rgrowth_c dtotindex_pc_c dprivateCredit_c fuelExports_c kaopen_c ability1_c  ///
	y1978-y2015 || imfcode: euro1 euro2, stddev cov(unstruct)
scalar sd_euro1 = exp(_b[lns1_1_1:_cons])
scalar sd_euro2 = exp(_b[lns1_1_2:_cons])
scalar sd_cons = exp(_b[lns1_1_3:_cons])
scalar corr_euro1_euro2 = _b[atr1_1_1_2:_cons]
scalar corr_cons_euro1 = _b[atr1_1_1_3:_cons]
scalar corr_cons_euro2 = _b[atr1_1_2_3:_cons]
estadd scalar sd_cons
estadd scalar sd_euro1
estadd scalar sd_euro2
estadd scalar corr_euro1_euro2
estadd scalar corr_cons_euro1
estadd scalar corr_cons_euro2
estimates store m9

mixed cu coord_m xr_fix c.coord_m#xr_fix lnfa_c govtDeficit_c stockcap_gdp_i_c finmed_gdp_i_c old_c young_c rgdppc_ppp_c ///
	rgrowth_c dtotindex_pc_c dprivateCredit_c fuelExports_c kaopen_c ability1_c eurocrisis ///
	y1978-y2015 || imfcode: xr_fix, stddev cov(unstruct)
scalar sd_xr = exp(_b[lns1_1_1:_cons])
scalar sd_cons = exp(_b[lns1_1_2:_cons])
scalar corr_cons_xr = _b[atr1_1_1_2:_cons]
estadd scalar sd_cons
estadd scalar sd_xr
estadd scalar corr_cons_xr
estimates store m10

mixed cu coord_m euro c.coord_m#euro lnfa_c govtDeficit_c stockcap_gdp_i_c finmed_gdp_i_c old_c young_c rgdppc_ppp_c ///
	rgrowth_c dtotindex_pc_c dprivateCredit_c fuelExports_c kaopen_c ability1_c eurocrisis ///
	y1978-y2015 || imfcode: euro, stddev cov(unstruct)
scalar sd_euro = exp(_b[lns1_1_1:_cons])
scalar sd_cons = exp(_b[lns1_1_2:_cons])
scalar corr_cons_euro = _b[atr1_1_1_2:_cons]
estadd scalar sd_cons
estadd scalar sd_euro
estadd scalar corr_cons_euro
estimates store m11

mixed cu coord_m euro1 euro2 c.coord_m#euro1 c.coord_m#euro2 lnfa_c govtDeficit_c stockcap_gdp_i_c finmed_gdp_i_c old_c young_c rgdppc_ppp_c ///
	rgrowth_c dtotindex_pc_c dprivateCredit_c fuelExports_c kaopen_c ability1_c  ///
	y1978-y2015 || imfcode: euro1 euro2, stddev cov(unstruct)
scalar sd_euro1 = exp(_b[lns1_1_1:_cons])
scalar sd_euro2 = exp(_b[lns1_1_2:_cons])
scalar sd_cons = exp(_b[lns1_1_3:_cons])
scalar corr_euro1_euro2 = _b[atr1_1_1_2:_cons]
scalar corr_cons_euro1 = _b[atr1_1_1_3:_cons]
scalar corr_cons_euro2 = _b[atr1_1_2_3:_cons]
estadd scalar sd_cons
estadd scalar sd_euro1
estadd scalar sd_euro2
estadd scalar corr_euro1_euro2
estadd scalar corr_cons_euro1
estadd scalar corr_cons_euro2
estimates store m12

esttab m7 m8 m9 m10 m11 m12 using "Table3.tex", replace nogaps title("Effect of exchange rate") ///
		mtitles("TB" "TB" "TB" "CU"  "CU"  "CU") nonumbers ///
		keep(coord_m xr_fix 1.xr_fix#c.coord_m ///
		euro 1.euro#c.coord_m euro1 euro2 1.euro1#c.coord_m 1.euro2#c.coord_m ///
		lnfa_c govtDeficit_c stockcap_gdp_i_c finmed_gdp_i_c old_c young_c rgdppc_ppp_c rgrowth_c dtotindex_pc_c dprivateCredit_c fuelExports_c kaopen_c ability1_c eurocrisis _cons) ///
		order(coord_m xr_fix 1.xr_fix#c.coord_m ///
		euro 1.euro#c.coord_m euro1 euro2 1.euro1#c.coord_m 1.euro2#c.coord_m ///
		lnfa_c govtDeficit_c stockcap_gdp_i_c finmed_gdp_i_c old_c young_c rgdppc_ppp_c rgrowth_c dtotindex_pc_c dprivateCredit_c fuelExports_c kaopen_c ability1_c eurocrisis _cons) ///
		drop(lns1_1_1:_cons lns1_1_2:_cons lns1_1_3:_cons atr1_1_1_2:_cons atr1_1_1_3:_cons atr1_1_2_3:_cons lnsig_e:_cons) ///
		varlabels(coord_m "Coord\${i}\$" xr_fix "XRfix\${i,t}\$" 1.xr_fix#c.coord_m "Coord\${i}\$*XRfix\${i,t}\$" ///
		euro "Euro\${i,t}\$" 1.euro#c.coord_m "Coord\${i}\$*Euro\${i,t}\$" ///
		euro1 "Euro1\${i,t}\$" 1.euro1#c.coord_m "Coord\${i}\$*Euro1\${i,t}\$" ///
		euro2 "Euro2\${i,t}\$" 1.euro2#c.coord_m "Coord\${i}\$*Euro2\${i,t}\$" ///
		lnfa_c "NFA\${i,t-1}\$" govtDeficit_c "Fiscal\${i,t}\$" stockcap_gdp_i_c "Stock\${i,t}\$" ///
		finmed_gdp_i_c "Intermed\${i,t}\$" old_c "Old\${i,t}\$" young_c "Young\${i,t}\$" rgdppc_ppp_c "GDPpc\${i,t}\$" rgrowth_c "Growth\${i,t}\$" dtotindex_pc_c "ToT\${i,t}\$" dprivateCredit_c "Credit\${i,t}\$" ///
		kaopen_c "KAOpen\${i,t}\$" fuelExports_c "FuelExp\${i,t}\$" ability1_c "OrigSin\${i,t}\$" eurocrisis "Eurocrisis\${i,t}\$" _cons Constant) ///
		cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.1 ** 0.05 *** 0.01) nonumbers ///
		stats(sd_cons sd_xr sd_euro sd_euro1 sd_euro2 corr_cons_xr corr_cons_euro corr_cons_euro1 corr_cons_euro2 corr_euro1_euro2 p N, fmt(%9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.3f %9.0f) labels("Sd(Cons)" "Sd(XRfix)" "Sd(Euro)" "Sd(Euro1)" "Sd(Euro2)" "Corr(Cons,XRfix)" "Corr(Cons,Euro)" "Corr(Cons,Euro1)" "Corr(Cons,Euro2)" "Corr(Euro1,Euro2)" "$ p $" "$ N $")) ///
		legend label collabels(, none) style(tex) ///
		notes addnotes("Standard errors in parentheses. *** $ p<0.01 $, ** $ p<0.05 $, * $ p<0.1 $.")

		
*********
* Table 4
*********

reg tb ltb coord govtDeficit_c stockcap_gdp_i_c finmed_gdp_i_c old_c young_c rgdppc_ppp_c rgrowth_c dtotindex_pc_c dprivateCredit_c fuelExports_c kaopen_c ability1_c eurocrisis y1978-y2015, robust
estimates store m13

ivreg2 tb ltb govtDeficit_c stockcap_gdp_i_c finmed_gdp_i_c old_c young_c rgdppc_ppp_c rgrowth_c dtotindex_pc_c dprivateCredit_c fuelExports_c kaopen_c ability1_c eurocrisis y1978-y2015 (coord = coord_75), robust cluster(imfcode) partial(y1978-y2015) first
estimates store m14

reg cu lcu coord govtDeficit_c stockcap_gdp_i_c finmed_gdp_i_c old_c young_c rgdppc_ppp_c rgrowth_c dtotindex_pc_c dprivateCredit_c fuelExports_c kaopen_c ability1_c eurocrisis y1978-y2015, robust
estimates store m15

ivreg2 cu lcu govtDeficit_c stockcap_gdp_i_c finmed_gdp_i_c old_c young_c rgdppc_ppp_c rgrowth_c dtotindex_pc_c dprivateCredit_c fuelExports_c kaopen_c ability1_c eurocrisis y1978-y2015 (coord = coord_75), robust cluster(imfcode) partial(y1978-y2015) first
estimates store m16

esttab m13 m14 m15 m16 using "Table4.tex", replace nogaps title("Effect of wage bargaining coordination -- panel models") ///
		mtitles("TB" "TB" "CU" "CU") nonumbers ///
		keep(ltb lcu coord govtDeficit_c stockcap_gdp_i_c finmed_gdp_i_c old_c young_c rgdppc_ppp_c rgrowth_c dtotindex_pc_c dprivateCredit_c fuelExports_c kaopen_c ability1_c eurocrisis _cons) ///
		order(ltb lcu coord govtDeficit_c stockcap_gdp_i_c finmed_gdp_i_c old_c young_c rgdppc_ppp_c rgrowth_c dtotindex_pc_c dprivateCredit_c fuelExports_c kaopen_c ability1_c eurocrisis _cons) ///
		varlabels(ltb "TB\${i,t-1}\$" lcu "CU\${i,t-1}\$" coord "Coord\${i,t}\$"  ///
		govtDeficit_c "Fiscal\${i,t}\$" stockcap_gdp_i_c "Stock\${i,t}\$" ///
		finmed_gdp_i_c "Intermed\${i,t}\$" old_c "Old\${i,t}\$" young_c "Young\${i,t}\$" rgdppc_ppp_c "GDPpc\${i,t}\$" rgrowth_c "Growth\${i,t}\$" dtotindex_pc_c "ToT\${i,t}\$" dprivateCredit_c "Credit\${i,t}\$" ///
		kaopen_c "KAOpen\${i,t}\$" fuelExports_c "FuelExp\${i,t}\$" ability1_c "OrigSin\${i,t}\$" eurocrisis "Eurocrisis\${i,t}\$" ///
		_cons Constant) ///
		cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.1 ** 0.05 *** 0.01) nonumbers ///
		stats(p N, fmt(%9.3f %9.0f) labels("$ p $" "$ N $")) ///
		legend label collabels(, none) style(tex) ///
		notes addnotes("Robust standard errors in parentheses. *** $ p<0.01 $, ** $ p<0.05 $, * $ p<0.1 $.")

		
		
		
